#include <fxp.h>
#include "hladata_parser.h"

bool parseHlaData(const char* file, HlaData& data)
{
    bool ret;
    ParseErrorData ped;

    FXParserLOV<set<string>, string> peptideParser("value", "pep");
        ignore_attr(peptideParser, "pos");

    FXParser<Sequence> sequenceParser("sequence");
        //add_lov_child(sequenceParser, "value", "pep", &Sequence::peptides);  This works but throws the warning due to 'pos'.
        add_attr(sequenceParser, "id", &Sequence::name);
        add_child(sequenceParser, &Sequence::peptides, peptideParser);

    FXParser<Haplotype> haplotypeParser("haplotype");
        add_child(haplotypeParser, &Haplotype::sequences, sequenceParser);
        add_attr(haplotypeParser, "id", &Haplotype::name);

    FXParser<Group> groupParser("group");
        add_child(groupParser, &Group::haplotypes, haplotypeParser);
        add_attr(groupParser, "id", &Group::name);

    FXPRootParser<HlaData> hlaParser("hla_calculus", groupParser);

    ret = parse_xml(file, data, hlaParser, ped, Warn, Warn);

    if (!ret)
        cerr << "XML ERROR: " << ped.error << " at line " << ped.line << endl;

    return ret;
}

